import threading
from time import sleep
import requests
from datetime import datetime
import datetime

seatid = '9192'

now = datetime.datetime.now()
tomorrow = now + datetime.timedelta(days=1)
tomorrowTime = tomorrow.strftime("%Y-%m-%d")

cookie = ''
headers = {
    'Cookie': cookie
}

if __name__ == '__main__':
    print('您将要预约的日期是：' + tomorrowTime)

    while 1:
        print('线程开启时间：', datetime.datetime.now())
        result = requests.get('http://seat.yangtzeu.edu.cn/libseat-ibeacon/saveBook?seatId=' + seatid + '&date='
                              + str(tomorrowTime) + '&start=' + str(510) + '&end=' + str(1290) + '&type=1&captchaToken=',
                              headers=headers).text
        print(result)
        if result[15:19] == 'succ':
            print('抢座成功，现在的时间是：', datetime.datetime.now())
            break
        if result[33:35] == '12' or result[33:35] == '13':
            print('超时，请更新cokkie')
            break
        if result[81:82] == '1':
            print('预约时间段有误 或 该时间段已有预约')
            break
        if result[86:87] == '1':
            print('未到预约时间，重新抢票中')
            sleep(0.5)
            continue
        print('抢座失败，重新抢票中')
        sleep(0.5)
